package com.hl.mapper;

import com.hl.pojo.Consultant;
import com.hl.pojo.ConsultationAppointment;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface ConsultationAppointmentMapper {

    @Insert("insert into consultation_appointment(user_id,time,consultant_id) value (#{userId},#{time},#{consultantId})")
    public Integer add(ConsultationAppointment consultationAppointment);

    @Select("select ca.*,ca.consultant_id caid,ca.time time2 from consultation_appointment ca where del = 0 and user_id = #{id} and time < now()")
    @Results({
            @Result(property = "consultant",column = "caid",many = @Many(select = "a"))
    })
    public List<ConsultationAppointment> findAll(Integer id);

    @Select("select ca.*,ca.consultant_id caid,ca.time time2 from consultation_appointment ca where del = 0 and user_id = #{id} and time >= now()")
    @Results({
            @Result(property = "consultant",column = "caid",many = @Many(select = "a"))
    })
    public List<ConsultationAppointment> findAll1(Integer id);
    @Select("select * from consultation_appointment where del = 0")
    public List<ConsultationAppointment> findAll2();
    @Select("select * from consultation_appointment where user_id = #{id} and del = 0")
    public List<ConsultationAppointment> findAll3(@Param("id") String id);

    @Select("select * from consultant where id=#{id}")
    public Consultant a(Integer id);

    @Update("update consultation_appointment set del=1 where id=#{id}")
    public Integer del(Integer id);
    @Update("update consultation_appointment set time=#{time},user_id=#{userId},consultant_id=#{consultantId} where id=#{id}")
    public Integer update(ConsultationAppointment consultationAppointment);
}
